<select id="getOrderCode" parameterType="cn.com.dragonpass.settle.model.dto.SupSettleDetailDTO$FillBusinessWay" resultType="cn.com.dragonpass.settle.model.dto.SupSettleDetailDTO$FillBusinessWayDto">
        select
            id, order_code orderCode
        from settle_sup_detail
        <where>
            1=1
            <if test="id!=null">
                and id > #{id}
            </if>
            <if test="startSettleTime != null">
                and settle_time >= #{startSettleTime}
            </if>
            <if test="endSettleTime != null">
                and #{endSettleTime} >= settle_time
            </if>
        </where>
        order by id
    </select>


     <select id="getOrderCode" parameterType="cn.com.dragonpass.settle.model.dto.SupSettleDetailDTO$FillBusinessWay" resultType="cn.com.dragonpass.settle.model.dto.SupSettleDetailDTO$FillBusinessWayDto">
        select
            id, order_code orderCode
        from settle_sup_detail
        <where>
            1=1
            <if test="id!=null">
                and id > #{id}
            </if>
            <if test="startSettleTime != null">
                and settle_time >= #{startSettleTime}
            </if>
            <if test="endSettleTime != null">
                and #{endSettleTime} >= settle_time
            </if>
        </where>
        order by id
    </select>

    ----------------------------------------------------------------------------------------------------------------------------
    public void pushRequestConfiV2() {
        RLock lock = redissonClient.getLock("pushRequestConfiV2");
        lock.lock();
        try {
            Integer curId = null;
            Queryable<SettleIncomeCostSap> result;

            boolean hasMoreData = true;
            while (hasMoreData) {
                Integer maxId = curId;
                result = settleIncomeCostSapDao.where(w -> {
                    w.setIfPushSap("N");
                    w.setDebitCreditCode("H");
                    if (maxId != null) {
                        w.setId(gt(maxId));
                    }
                });
                List<SettleIncomeCostSap> settleIncomeCostSaps = result.orderByAsc((w -> list(w.getId()))).toList(limit);
                if (CollectionUtil.isEmpty(settleIncomeCostSaps)) {
                    hasMoreData = false;
                } else {
                    // 获取settleIncomeCostSaps集合 最后一个ID
                    curId = settleIncomeCostSaps.get(settleIncomeCostSaps.size() - 1).getId();

                    try {
                        this.incomeCostSapPushToSAP(settleIncomeCostSaps);
                    } catch (Exception e) {
                        log.error("创建日记账分录失败【Cause={} - Message={} stackTrace={}】", e.getCause(), e.getMessage(), Arrays.deepToString(e.getStackTrace()));
                        break;
                    }
                }
            }
        } finally {
            if (lock != null) {
                lock.unlock();
            }
        }
    }

     public void fillBusinessWay(SupSettleDetailDTO.FillBusinessWay input) throws ParseException {
        java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd");
        java.text.SimpleDateFormat start = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        java.text.SimpleDateFormat end = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        Integer pageIndex = 1;
        for(int i=0;i<input.getDates().size();i++){
            input.setSettleTime(input.getDates().get(i));
            String format = sdf.format(input.getSettleTime());
            String s1 = format + " 00:00:00";
            String s2 = format + " 23:59:59";
            input.setStartSettleTime(start.parse(s1));
            input.setEndSettleTime(end.parse(s2));
            log.info("填充业务方式 {}", format);
            boolean hasMorePages = true;
            while (hasMorePages) {
                PageHelper.startPage(pageIndex,600);
                List<SupSettleDetailDTO.FillBusinessWayDto> list = settleSupDetailMapper.getOrderCode(input);
                if(CollectionUtil.isEmpty(list)){
                    hasMorePages = false;
                    continue;
                }
                input.setId(list.get(list.size()-1).getId());
                Map<String, Long> map = new HashMap<>();
                List<String> orderNos = new ArrayList<>();
                list.forEach(l->{
                    if(StringUtils.isNotEmpty(l.getOrderCode())){
                        map.put(l.getOrderCode(), l.getId());
                        orderNos.add(l.getOrderCode());
                    }
                });

                List<Tuple7<String, String,String,String,String,String,String>> bws = settleCusDetailDao.where(x -> x.setClientOrderNo(in(orderNos))).toTuple7(w -> tuple(w.getClientOrderNo(), w.getBusinessWay(), w.getAgreementCode(), w.getAgreementName(), w.getSettlementCode(), w.getCusCode(), w.getCusName()));
                if(CollectionUtil.isEmpty(bws)){
                    continue;
                }

                List<SupSettleDetailDTO.FillBusinessWayDto> sup = new ArrayList<>();
                bws.forEach(l->{
                    SupSettleDetailDTO.FillBusinessWayDto s = new SupSettleDetailDTO.FillBusinessWayDto();
                    s.setId(map.get(l.getF1()));
                    s.setBusinessWay(l.getF2());
                    s.setSalesAgreementCode(l.getF3());
                    s.setSalesAgreementName(l.getF4());
                    s.setSettlementCode(l.getF5());
                    s.setCusCode(l.getF6());
                    s.setCusName(l.getF7());
                    sup.add(s);
                });
                List<List<SupSettleDetailDTO.FillBusinessWayDto>> partition = Lists.partition(sup, 200);
                for(List<SupSettleDetailDTO.FillBusinessWayDto> li : partition){
                    settleSupDetailMapper.fillBusinessWay(li);
                }
//            PageInfo page = new PageInfo(list);
//            if (pageIndex > page.getPages()) {
//                hasMorePages = false;
//            }
            }
        }
    }